import 'package:demo/app/global.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '../../routes/app_pages.dart';
import '../../widgets/CommonDialog.dart';

class MainController extends GetxController {

  var platform = const MethodChannel("sing.top/rth");
  int listSize = 4; // 有多少个list，是否开启产品
  RxInt currentIndex = 0.obs;
  var lastBackPressTime = -1;

  void setCurrentIndex(index){
    currentIndex.value = index;
    update();
  }

  @override
  void onInit() {
    super.onInit();
    listSize = Global.isAuditing ? 3 : 4;

    platform.setMethodCallHandler(flutterMethod);
  }

  Future<dynamic> flutterMethod(MethodCall methodCall) async {
    switch (methodCall.method) {
      case 'toLogin':
        Get.offAllNamed(Routes.LOGIN);
        break;
      case 'toApply':
        Get.toNamed(Routes.APPLY);
        break;
    }
  }


  /// 拨打客服
  void call(){
    Get.dialog(
      CommonDialog(
        contentStr:'您确定要拨打客服电话吗？',
        yesFun: ()=> platform.invokeMethod('toCall'),
      ),
    );
  }

  /// 申请借款
  void apply(){
    Get.toNamed(Routes.APPLY);
  }

  /// 订单中心 1待确认、2待还款、3已逾期、4审核中、0全部订单
  void toOrder(int type){
    Get.toNamed(Routes.ORDER,arguments: {'type' : type});
  }

  void toCalc(){
    // Get.toNamed(Routes.CALC);
    platform.invokeMethod('toCalc');
  }

  /// 0借款指南  1还款指南  2完善信息   3极速审核  4立即放款
  void toHint(int type){
    Get.toNamed(Routes.HINT, parameters: {'type': '$type'});
  }

  /// 关于我们
  void toAbout(){
    Get.toNamed(Routes.ABOUT);
  }

  /// 意见反馈
  void toBackFeed() async {
    Get.toNamed(Routes.FEEDBACK);
  }
}
